package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TMarryImage;
import com.ruoyi.marry.service.ITMarryImageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 婚纱照Controller
 *
 * @author user_marry
 * @date 2020-11-19
 */
@RestController
@RequestMapping("/marry/marryImage")
public class TMarryImageController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(TMarryImageController.class);

    @Autowired
    private ITMarryImageService tMarryImageService;

    /**
     * 查询婚纱照列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMarryImage tMarryImage) {
        tMarryImage.setType("001");
        startPage();
        List<TMarryImage> list = tMarryImageService.selectTMarryImageList(tMarryImage);
        return getDataTable(list);
    }

    /**
     * 导出婚纱照列表
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:export')")
    @Log(title = "婚纱照", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TMarryImage tMarryImage) {
        List<TMarryImage> list = tMarryImageService.selectTMarryImageList(tMarryImage);
        ExcelUtil<TMarryImage> util = new ExcelUtil<TMarryImage>(TMarryImage.class);
        return util.exportExcel(list, "userImage");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tMarryImageService.selectTMarryImageById(id));
    }

    /**
     * 新增保存婚纱照
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:add')")
    @Log(title = "婚纱照", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TMarryImage tMarryImage) {
        return toAjax(tMarryImageService.insertTMarryImage(tMarryImage));
    }

    /**
     * 修改婚纱照
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:edit')")
    @Log(title = "婚纱照", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMarryImage tMarryImage) {
        return toAjax(tMarryImageService.updateTMarryImage(tMarryImage));
    }

    /**
     * 删除婚纱照
     */
    @PreAuthorize("@ss.hasPermi('marry:marryImage:remove')")
    @Log(title = "婚纱照", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tMarryImageService.deleteTMarryImageByIds(ids));
    }
}
